﻿// Copyright 2016 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Collections.Generic;
using UnityEngine;

namespace GVR.Entity {
  /// <summary>
  /// Attach this to a parent gameobject to reset all children objects
  /// to an initial state when ResetScene is called. ResetScene
  /// should be hooked to an input event. Add SceneReseter functionality
  /// to a component by implementing IResetable.
  /// </summary>
  /// <seealso cref="UnityEngine.MonoBehaviour" />
  public class SceneReseter : MonoBehaviour {
    void Start() {
      _resetables = new List<IResetable>(GetComponentsInChildren<IResetable>());
    }

    /// <summary>
    /// Reset all child IResetable objects.
    /// </summary>
    public void ResetScene() {
      _resetables.ForEach(r => { r.ResetObject(transform); });
    }

    private List<IResetable> _resetables;
  }
}
